<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改评论')"/>
</head>
<body>
<form class="layui-form" th:object="${comment}">
    <div class="mainBox">
        <div class="main-container">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="layui-form-item">
                <label class="layui-form-label">是否管理员：</label>
                <div class="layui-input-block">
                    <div class="radio-box" radio-dict-code="input"
                        th:attr="default-value=*{adminComment}" name="adminComment">
                    </div>
                </div>
           </div>
            <div class="layui-form-item">
                <label class="layui-form-label">游客头像：</label>
                <div class="layui-input-block">
                    <input type="text" name="avatar" th:field="*{avatar}"
                        placeholder="请输入游客头像" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">评论内容：</label>
                <div class="layui-input-block">
                    <input type="text" name="content" th:field="*{content}"
                        placeholder="请输入评论内容" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱：</label>
                <div class="layui-input-block">
                    <input type="text" name="email" th:field="*{email}"
                        placeholder="请输入邮箱" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">昵称：</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname" th:field="*{nickname}"
                        placeholder="请输入昵称" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">博客id：</label>
                <div class="layui-input-block">
                    <input type="text" name="blogId" th:field="*{blogId}"
                        placeholder="请输入博客id" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上级评论id：</label>
                <div class="layui-input-block">
                    <input type="text" name="parentCommentId" th:field="*{parentCommentId}"
                        placeholder="请输入上级评论id" class="layui-input" />
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="comment-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery', 'laydate', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        let prefix = "";


        form.on('submit(comment-update)', function (data) {
            for (var key in data.field) {
                var type = $(data.form).find("input[name='" + key + "']").attr("type");
                if (type == "checkbox") {
                    var value = "";
                    $(data.form).find("input[name='" + key + "']:checked").each(function () {
                        value += $(this).val() + ",";
                    })
                    if (value != "") {
                        value = value.substr(0, value.length - 1);
                        data.field[key] = value;
                    }

                }
            }
            $.ajax({
                url: prefix + 'update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'put',
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("comment-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    });
</script>
</html>